program on JFrame
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mani2
{
public static void main(String args[])
{
JFrame frame=new JFrame("vision");
frame.addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
});
JLabel L=new JLabel(" ");
//L.setPreferedSize(new Dimension(175,100));
frame.getContentPane().add(L);
frame.pack();
frame.setVisible(true);
}
}
program on JWindow
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mani3 extends JWindow
{
int x=0,y=0;
public mani3()
{
setBounds(60,60,100,100);
addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
});
addMouseListener(new MouseAdapter(){
public void MousePressed(MouseEvent e)
{
x=e.getX();
y=e.getY();
System.out.println(x+" "+y);
}
});
addMouseMotionListener(new MouseMotionAdapter(){
public void MouseDragged(MouseEvent e)
{
setLocation(getLocation().x+(e.getX()-x),getLocation().y+(e.getY()-y));
}
});
}
public static void main(String args[])
{
new mani3();
}
}
program to calculate area of triangle using frames
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mani4 extends JFrame implements ActionListener
{
JTextField t1,t2,t3;
public static void main(String args[])
{
new mani4();
}
mani4()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
JButton jb;
t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(10);
jb=new JButton("press");
jb.addActionListener(this);
cp.add(t1);
cp.add(t2);
cp.add(t3);
cp.add(jb);
setSize(new Dimension(200,200));
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int b,h,a;
String s;
s=t1.getText();
b=Integer.parseInt(s);
s=t2.getText();
h=Integer.parseInt(s);
a=(b*h)/2;
t3.setText(""+a);
}
}
program to calculate area of triangle using applet
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class mani5 extends JApplet implements ActionListener
{
JTextField t1,t2,t3;
JButton jb;
public void init()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(10);
jb=new JButton("press");
jb.addActionListener(this);
cp.add(t1);
cp.add(t2);
cp.add(t3);
cp.add(jb);
}
public void actionPerformed(ActionEvent e)
{
int b,h,a;
String s;
s=t1.getText();
b=Integer.parseInt(s);
s=t2.getText();
h=Integer.parseInt(s);
a=(b*h)/2;
t3.setText(""+a);
}
}
/*<applet code=mani5 width=100 height=100>
</applet>*/
program on JButton.
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent.*;
import javax.swing.*;
public class mani6 extends JApplet implements ActionListener
{
JTextField jtf;
public void init()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
ImageIcon i1=new ImageIcon("image2.gif");
ImageIcon i2=new ImageIcon("image1.gif");
JButton b1=new JButton(i1);
b1.setRolloverIcon(i2);
b1.setActionCommand("Sri lakshmi Doing Very well");
b1.addActionListener(this);
cp.add(b1);
jtf=new JTextField(15);
cp.add(jtf);
}
public void actionPerformed(ActionEvent ae)
{
jtf.setText(ae.getActionCommand());
}
}
/* <applet code=mani6 width=200 height=200>
</applet> */
program to calculate grade of students using frames
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mani7 extends JFrame implements ActionListener
{
JTextField m,p,c,tot,avg,gr;
JButton jb;
public static void main(String args[])
{
new mani7();
}
mani7()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
m=new JTextField(5);
p=new JTextField(5);
c=new JTextField(5);
tot=new JTextField(5);
avg=new JTextField(5);
gr=new JTextField(20);
jb=new JButton("Click Me");
jb.addActionListener(this);
JLabel l1,l2,l3,l4,l5,l6;
l1=new JLabel("Maths");
l2=new JLabel("PHysics");
l3=new JLabel("Chemistry");
l4=new JLabel("Total");
l5=new JLabel("Average");
l6=new JLabel("Grade");
cp.add(l1);
cp.add(m);
cp.add(l2);
cp.add(p);
cp.add(l3);
cp.add(c);
cp.add(l4);
cp.add(tot);
cp.add(l5);
cp.add(avg);
cp.add(l6);
cp.add(gr);
cp.add(jb);
setSize(200,200);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int m1,p1,c1,tot1,avg1;
String s;
s=m.getText();
m1=Integer.parseInt(s);
s=p.getText();
p1=Integer.parseInt(s);
s=c.getText();
c1=Integer.parseInt(s);
tot1=m1+p1+c1;
avg1=tot1/3;
tot.setText(""+tot1);
avg.setText(""+avg1);
if(avg1>=35&&avg1<50)
gr.setText("pass");
else
if(avg1>50&&avg1<60)
gr.setText("second");
else
if(avg1>60)
gr.setText("first");
else
gr.setText("fail");
}
}